<?php
	function GetNews($id_news)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_news=='all')
		{
			$query=mysql_query("select * from news order by date desc;",$connect);
		}
		else
		{
			$query=mysql_query("select * from news where id_news='$id_news';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function GetListTour()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select id_tour,title,description,image from tour where pindex=0 order by date desc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetAllListTour()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select id_tour,title,description,image from tour order by date desc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetListTourIndex()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select id_tour,title,description,image from tour where pindex=1 order by date desc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetListTourPlace($id_dd)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select id_tour,title,description,image from tour where id_come_place='$id_dd' order by date desc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetTour($id_tour)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from tour where id_tour='$id_tour';",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddTourRegister($id_register,$hoten,$congty,$sdt,$fax,$email,$diachi,$ngaykh,$slk,$yc,$tour_id)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into register_tour values ('$id_register', '$hoten', '$congty', '$sdt', '$fax', '$email', '$diachi', '$ngaykh', $slk,'$yc', curdate(), '$tour_id');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetPassword($usename)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select password from profile where usename='$usename';",$connect);
		while($row=mysql_fetch_array($query))
		{
			$pass=$row[0];
		}
		return $pass;
		mysql_close($connect);
	}
	function GetTypeOfRoom()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from typeofroom order by price asc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetTypeListRoom($id_type)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from room where id_type='$id_type';",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddRoomRegister($hoten,$congty,$sdt,$fax,$email,$diachi,$comeday,$goday,$requiet,$idloai,$tenloai,$soluong)
	{
		$id_register=substr(md5(rand(0,999)),6,10);
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into register_room values ('$id_register', '$hoten', '$congty', '$sdt', '$fax', '$email', '$diachi', '$comeday','$goday', '$requiet', '$idloai', '$tenloai', $soluong, curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function UpdateRoomRegister($id_type, $sldk)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update typeofroom set dadangky=dadangky+$sldk where id_type='$id_type';",$connect);
		mysql_close($connect);
	}
	function AddIdear($hoten,$noidung)
	{
		$id_idear=substr(md5(rand(0,999)),6,10);
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into idearofgust values ('$id_idear', '$hoten', '$noidung', curdate(), 0);",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function AddNews($title,$content)
	{
		$id_news=substr(md5(rand(0,999)),6,10);
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into news values ('$id_news', '$title', '$content', curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function UpdateNews($id,$tieude,$nd)
	{
		
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update news set title='$tieude', content='$nd' where id_news='$id';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteNews($id_news)
	{
		
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from news where id_news='$id_news';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetComePlace()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from come_place;",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddTour($id_tour,$id_come_place,$title,$description,$detail,$image,$dltc)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into tour values ('$id_tour', '$id_come_place', '$title', '$description', '$detail', '$image',$dltc, curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function UpdateTour($id_tour,$id_come_place,$nametour,$description,$detail,$dltc)
	{
		
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if(!$detail)
		{
			$query=mysql_query("update tour set id_come_place='$id_come_place', title='$nametour', description='$description', pindex=$dltc where id_tour='$id_tour';",$connect);
			//echo 'Khong Cap nhat';
		}
		else
		{
			$query=mysql_query("update tour set id_come_place='$id_come_place', title='$nametour', description='$description', detail='$detail', pindex=$dltc where id_tour='$id_tour';",$connect);
			//echo 'Cap nhat';
		}
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteTour($id_tour)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query0=mysql_query("select image from tour where id_tour='$id_tour';",$connect);
		while($row=mysql_fetch_array($query0))
		{
			$filename=$row[0];
		}
		if(unlink($filename))
		{
			$query=mysql_query("delete from tour where id_tour='$id_tour';",$connect);
			$log=mysql_error($connect);
		}
		return $log;
		mysql_close($connect);
	}
	function AddEmployment($content)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$id_note=substr(md5(rand(0,999)),10,10);
		$query=mysql_query("insert into need_employer values('$id_note','$content',curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function LayDanhSachTuyenDung($id_note)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_note=='all')
		{
			$query=mysql_query("select * from need_employer order by date desc;",$connect);
		}
		else
		{
			$query=mysql_query("select * from need_employer where id_note='$id_note';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function UpdateEmployment($id,$nd)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update need_employer set content='$nd' where id_note='$id';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteEmployment($id_note)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from need_employer where id_note='$id_note';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function AddImage($id_image,$path)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into image values('$id_image','$path',curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListImage($id_image)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_image=='all')
		{
			$query=mysql_query("select * from image order by date desc;",$connect);
		}
		else
		{
			$query=mysql_query("select * from image where id_image='$id_image';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function DeleteImage($id_image)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from image where id_image='$id_image';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListPlace($id_place)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_place=='all')
		{
			$query=mysql_query("select * from come_place;",$connect);
		}
		else
		{
			$query=mysql_query("select * from come_place where id_come_place='$id_place';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function AddPlace($id_place,$name)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into come_place values('$id_place','$name');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeletePlace($id_place)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from come_place where id_come_place='$id_place';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function TangLuotTruyCap()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update visitor set value=value+1 where name='ltc';",$connect);
		mysql_close($connect);
	}
	function LayLuotTruyCap()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select value from visitor where name='ltc';",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetListRegister()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select *,title from register_tour, tour where register_tour.id_tour = tour.id_tour order by register_tour.date desc;",$connect);
		return $query;
		mysql_close($connect);
	}
	function DeleteListRegister($id_register)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from register_tour where id_register='$id_register';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function AddRoom($tenphong, $soluongkhach, $giaphong, $soluongphong)
	{
		$id_type=substr(md5(rand(0,999)),4,10);
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert  into typeofroom values('$id_type', '$tenphong', $soluongkhach, $giaphong, $soluongphong,0);",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListRoom($id_type)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_type=='all')
		{
			$query=mysql_query("select * from typeofroom;",$connect);
		}
		else
		{
			$query=mysql_query("select * from typeofroom where id_type='$id_type';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function UpdateRoom($id_type,$tenphong, $soluongkhach, $giaphong, $soluongphong)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update typeofroom set name_type='$tenphong', passenger=$soluongkhach, price=$giaphong, soluong=$soluongphong where id_type='$id_type';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteRoom($id_type)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from typeofroom where id_type='$id_type';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function UpdateRegisterRoom($id_type,$giatri)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update typeofroom set dadangky=dadangky-$giatri where id_type='$id_type';",$connect);
		mysql_close($connect);
	}
	function GetListRegisterRoom($id_register)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_register=='all')
		{
			$query=mysql_query("select * from register_room order by date desc;",$connect);
		}
		else
		{
			$query=mysql_query("select * from register_room where id_register='$id_register';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function DeleteListRegisterRoom($id_register)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from register_room where id_register='$id_register';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function UpdatePassword($newpass)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update profile set password='$newpass' where usename='admin';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListGopY($id_idear)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($id_idear=='all')
		{
			$query=mysql_query("select * from idearofgust order by date desc;",$connect);
		}
		else
		{
			$query=mysql_query("select * from idearofgust where id_idear='$id_idear';",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function UpdateIdear($id_idear)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("update idearofgust set status=1 where id_idear='$id_idear';",$connect);
		mysql_close($connect);
	}
	function DeleteIdear($id_idear)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from idearofgust where id_idear='$id_idear';",$connect);
		mysql_close($connect);
	}
	function GetCompany()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from company_name;",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddCompany($id_congty,$tencongty)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into company_name values('$id_congty','$tencongty');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteCompany($id_congty)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from company_name where id_company='$id_congty';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetCountry($id_company)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select country.name,country.id_country from country,company_country where company_country.id_company='$id_company' and company_country.id_country=country.id_country;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetListCountry()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from country;",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddCountry($id_quocgia,$tenquocgia)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into country values('$id_quocgia','$tenquocgia');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteCountry($id_quocgia)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from country where id_country='$id_quocgia';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetProvice($id_country)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from provice where id_country='$id_country';",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddCity($id_thanhpho,$id_country,$tenthanhpho)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into provice values('$id_thanhpho','$id_country','$tenthanhpho');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteCity($id_thanhpho)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from provice where id_provice='$id_thanhpho';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListCity()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select id_provice as idprovice, provice.name as pname, country.name as cname from provice, country where provice.id_country=country.id_country order by cname;",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddRegisterTicket($hoten, $sdt, $congty, $loai, $noidi, $noiden, $ngaydi, $ngayve, $nguoilon, $treem, $embe)
	{
		$id_register=substr(md5(rand(0,999)),2,10);
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into register_ticket values('$id_register' , '$hoten', '$sdt', '$congty', '$loai', '$noidi', '$noiden', '$ngaydi', '$ngayve', $nguoilon, $treem, $embe, curdate());",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListRegisterTicket()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select * from register_ticket, company_name where register_ticket.congty=company_name.id_company;",$connect);
		return $query;
		mysql_close($connect);
	}
	function GetProviceFromRegister($loai)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		if($loai=='noidi')
		{
			$query=mysql_query("select * from register_ticket, provice where register_ticket.noidi=provice.id_provice;",$connect);
		}
		else
		{
			$query=mysql_query("select * from register_ticket, provice where register_ticket.noiden=provice.id_provice;",$connect);
		}
		return $query;
		mysql_close($connect);
	}
	function DeleteRegisterTicket($id_register)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from register_ticket where id_register='$id_register';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function GetListCompanyCountry()
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("select company_name.name as tencongty, country.name as tenquocgia, company_country.id_company as idcongty, company_country.id_country as idquocgia  from company_name, country, company_country where company_country.id_company=company_name.id_company and company_country.id_country = country.id_country order by tencongty;",$connect);
		return $query;
		mysql_close($connect);
	}
	function AddCompanyCountry($id_company,$id_country)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("insert into company_country values('$id_company','$id_country');",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
	function DeleteCompanyCountry($id_congty,$id_quocgia)
	{
		include("imp/connect_db.php");
		mysql_query("SET NAMES 'utf8'");
		$query=mysql_query("delete from company_country where id_company='$id_congty' and id_country='$id_quocgia';",$connect);
		$log=mysql_error($connect);
		return $log;
		mysql_close($connect);
	}
?>